package com.comptel.actions.example;

import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.comptel.actions.Action;
import com.comptel.actions.ActionProvider;
import com.comptel.actions.ActionResult;

public abstract class ActionProviderTemplate implements ActionProvider, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static List<Action> emptyList = new ArrayList<Action>();
	protected Map<Class<?>,List<Action>> allActions = new HashMap<Class<?>,List<Action>>();
	
	@Override
	public String getProviderName() {
		return this.getClass().getName();
	}

	@Override
	public Iterable<Action> getActions(Object dobj) {
		return allActions.get(dobj.getClass()) == null ? emptyList : allActions.get(dobj.getClass()); 
	}
	
	@Override
	public ActionResult runAction(Action action, Object obj) {
		return action.execute(obj);
	}
	
}
